package com.hzau.tourist_service_sys.comtroller;

import com.hzau.tourist_service_sys.pojo.Hotel.Discount;
import com.hzau.tourist_service_sys.pojo.Hotel.Hotel;
import com.hzau.tourist_service_sys.pojo.Hotel.HotelOrders;
import com.hzau.tourist_service_sys.pojo.Hotel.Sell;
import com.hzau.tourist_service_sys.result.Result;
import com.hzau.tourist_service_sys.service.HotelService;
import com.hzau.tourist_service_sys.ultils.jjwttool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HotelController {
    @Autowired
    HotelService hotelService;
    /*按照条件查询酒店*/
    @PostMapping("/hotel/search")
    public Result search(@RequestBody Hotel hotel){

        return  hotelService.search(hotel);
    }
    /*按照酒店Id查选房间信息*/
    @PostMapping("/hotel/infofind")
        public Result infoFind(@RequestBody Hotel hotel){return  hotelService.infoFind(hotel);}
    /*按照酒店Id查选所有订单*/
    @PostMapping("/hotel/findAllOrders")
    public  Result  findAllOrders(@RequestBody  Hotel hotel){

        return hotelService.findAllOrders(hotel.getHotelId(),hotel.getPagenum());
    };
    /*根据订单id详细信息*/
    @GetMapping("/hotel/findOrderDetails/{HR_id}&&{hotelId}")
    public  Result findOrderDetails(@PathVariable Integer HR_id,@RequestPart(required = false) @PathVariable Integer hotelId){
        return  hotelService.findOrderDetails(HR_id,hotelId);
    }
    /*插入新订单*/
    @PostMapping("hotel/insertOrders")
    public Result insertOrders(@RequestBody HotelOrders hotelOrders){
         return  hotelService.insertOrders(hotelOrders);
    }
    /*订单信息更新*/
    @PostMapping("/hotel/hotelUpdateOrders")
    public  Result hotelUpdateOrders(@RequestBody HotelOrders hotelOrders){
        return  hotelService.hotelUpdateOrders(hotelOrders);
    }
/*    查看优惠,
    * 注释原因:业务逻辑不对,设计背大锅*/
    @GetMapping("/hotel/hotelFindAllDiscount/{hotelId}")
    public Result hotelFindAllDiscount(long hotelId){
        return  hotelService.hotelFindAllDiscount(hotelId);
    }
//    插入优惠
    @PostMapping("/hotel/insertDiscount")
    public Result insertDiscount(@RequestBody Discount discount){
        return hotelService.insertDiscount(discount);
    }

    @GetMapping("/hotel/deleteDiscount/{hotelId}&&{roomType}")
    public Result deleteDiscount(@PathVariable long hotelId,@PathVariable int roomType){
        return  hotelService.deleteDiscount(hotelId,roomType);
    }
    /*
    *  查询所有房型及其价格*/
    @PostMapping("/hotel/selectAllPrice")
    public Result selectAllPrice(@RequestBody  Hotel hotel){
        return  hotelService.selectAllPrice(hotel.getHotelId(),hotel.getPagenum());
    }
    /*产看营业额*

     */
    @GetMapping("/hotel/caculateRevenue/{hotelId}")
    public Result calculateRevenue(@PathVariable long hotelId){
        return hotelService.calculateRevenue(hotelId);
    }
    /*查询剩余房间*/
    @GetMapping("/hotel/caculateRestRooms/{hotelId}")
    public Result calculateRestRooms(@PathVariable long hotelId){
        return hotelService.calculateRestRooms(hotelId);
    }
    /*酒店信息
    * */
    @GetMapping("/hotel/hotelInfo/{hotelId}")
    public Result hotelInfo(@PathVariable long hotelId){
        return hotelService.hotelInfo(hotelId);
    }
    /*促销信息分页*/
    @GetMapping("/hotel/selectAllSells/{pagenum}")
    public Result selectAllSells(@PathVariable int pagenum){
        return hotelService.selectAllSells(pagenum);
    }
    /*促销详情
    * */
    @GetMapping("/hotel/sellDetails/{recommendId}")
    public Result sellDetails(@PathVariable long recommendId){
        return hotelService.sellDetails(recommendId);
    }
    /*删除促销*/
    @GetMapping("hotel/deleteSells{recommendId}")
    public Result deleteSells(@PathVariable long recommendId){
        return  hotelService.deleteSells(recommendId);
    }
    /*新增促销*/
    @PostMapping("/hotel/insertSells")
    public Result inserSells(@RequestBody Sell sell){
        return hotelService.insertSells(sell);
    }
    /*预定查看,业务逻辑有问题,设计再背大锅*/
//    @PostMapping("/hotel/findpre")
//    public Result findPre(int pagenum){
//        return hotelService.findPre(pagenum);
//    }
    @PostMapping("/hotel/getHotelByAdminId")
    public  Result getHotelByAdminID(HttpServletRequest request){
        Integer userId=0;
        String token=request.getHeader("token");{
             userId = jjwttool.getUserId(token);
        }
        return hotelService.getHotelByAdminId(userId);
    }

}
